#include <unittest++/UnitTest++.h>
#include <string>

#include "numericoperations.h"

using std::string;

SUITE(NumericOperationsTest)
{
    TEST(TestClipInteger)
    {
		int integer = 80;
		NumericOperations::clip(integer, 0, 100);
		CHECK_EQUAL(80, integer);
		
		integer = 80;
		NumericOperations::clip(integer, 0, 50);
		CHECK_EQUAL(50, integer);
		
		integer = 80;
		NumericOperations::clip(integer, 90, 100);
		CHECK_EQUAL(90, integer);
    }
	
	TEST(TestClipFloatingPoint)
    {
		float fp = 80.f;
		NumericOperations::clip(fp, 0.f, 100.f);
		CHECK_CLOSE(80.f, fp, 0.00001);
		
		fp = 80.f;
		NumericOperations::clip(fp, 0.f, 50.f);
		CHECK_CLOSE(50.f, fp, 0.00001);
		
		fp = 80.f;
		NumericOperations::clip(fp, 90.f, 100.f);
		CHECK_CLOSE(90.f, fp, 0.00001);
    }
    
    TEST(TestToString)
    {
        string numericString;
        
        NumericOperations::toString(80, numericString);
		CHECK_EQUAL("80", numericString);
        
        NumericOperations::toString(-60, numericString);
		CHECK_EQUAL("-60", numericString);
        
        NumericOperations::toString(0, numericString);
		CHECK_EQUAL("0", numericString);
        
        NumericOperations::toString(66.234, numericString);
		CHECK_EQUAL("66.234", numericString);
        
        NumericOperations::toString(-34.9873, numericString);
		CHECK_EQUAL("-34.9873", numericString);
    }
}
